//
//  MPWuJiangViewController.m
//  MobileProject
//
//  Created by caiqilin on 2017/6/16.
//  Copyright © 2017年 caiqilin. All rights reserved.
//

#import "MPWuJiangViewController.h"
//#import <BmobSDK/Bmob.h>
#import "MJExtension.h"
#import "MPWuJiang.h"
#import "NSDictionary+IBExtension.h"
#import "MPTopCardViewCell.h"
#import "UIImageView+WebCache.h"
@interface MPWuJiangViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (strong , nonatomic) UITableView *table;
@property (nonatomic, strong) NSArray *bannerList;
@property (nonatomic, strong) NSString *skinWebsite;
@property (nonatomic, strong) NSString *preWebsite;
@property (nonatomic, strong) NSString *no;

@end

@implementation MPWuJiangViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
//    BmobQuery *bmobQuery = [[BmobQuery alloc] init];
//    NSString *bql = @"select * from sgs_assit_wujiang where pack = ? and name = ?";
//    
//    NSArray *placeholderArray = @[_pack,_name];
//    [bmobQuery queryInBackgroundWithBQL:bql pvalues:placeholderArray block:^(BQLQueryResult *result, NSError *error) {
//        if (error) {
//            NSLog(@"%@",error);
//        } else {
//            if (result) {
//                NSLog(@"%@",result.resultsAry);
//                
//                BmobObject *obj = result.resultsAry.firstObject;
//                self.skinWebsite = [obj objectForKey:@"skin_website"];
//                self.preWebsite = [obj objectForKey:@"pre_website"];
//
//                self.no = [obj objectForKey:@"no"];
//                
//                [self.table reloadData];
//
//                NSLog(@"obj.playerName = %@", [obj objectForKey:@"skin_website"]);
//                NSLog(@"obj.playerName = %@", [obj objectForKey:@"no"]);
//
//                //打印objectId,createdAt,updatedAt
//                NSLog(@"obj.objectId = %@", [obj objectId]);
//                NSLog(@"obj.createdAt = %@", [obj createdAt]);
//                NSLog(@"obj.updatedAt = %@", [obj updatedAt]);
//
//            }
//        }
//    }];
    
    [self initView];
    
}

- (void)initView {
    self.table = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, SCREEN_HEIGHT -49) style:UITableViewStyleGrouped];
    self.table.delegate = self;
    self.table.dataSource = self;
    self.table.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:self.table];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //    if (section == 0) {
    //        return 2;
    //    } else if (section == 1) {
    //        return 2;
    //    }
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MPTopCardViewCell *orderManageCell = [MPTopCardViewCell cellWithTableView:tableView];
    NSString *str = [NSString stringWithFormat:@"%@%@00.png",self.skinWebsite,self.no];
    NSString *smallStr = [NSString stringWithFormat:@"%@%@k.png",self.preWebsite,self.no];

    [orderManageCell.wuImage sd_setImageWithURL:[NSURL URLWithString:str]];
    [orderManageCell.smallWuImageView sd_setImageWithURL:[NSURL URLWithString:smallStr]];

    return orderManageCell;
    
}

//- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
//    if (section == 0) {
//        return @"订单管理";
//    }else if (section == 1) {
//        return @"学习互动社区";
//    }
//    return @"新转保名单管理";
//}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 300;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.1;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //    if (indexPath.section == 1) {
    //        ibRecommendController *recommend = [[ibRecommendController alloc] init];
    //        [self.navigationController pushViewController:recommend animated:YES];
    //    }
}

- (NSData *)toJSONData:(id)theData{
    
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:theData
                                                       options:NSJSONWritingPrettyPrinted
                                                         error:&error];
    
    if ([jsonData length] > 0 && error == nil){
        return jsonData;
    }else{
        return nil;
    }
}


@end
